<template>
  <div class="main">
    <div class="card-content">
      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <span>{{ alert1List[questionId] }}</span>
        </div>
        <el-divider />
        <div v-for="(Question, index) in currentQuestion">
          <!-- 单选 -->
          <div
            class="q-single"
            v-show="
              Question.questionType == 2 && showList[questionId][index] === 1
            "
          >
            <div class="question">
              {{ index + 1 }}. {{ Question.questionstem }}
            </div>
            <div class="tip" :style="{ width: tipwidth }" v-if="Question.tip">
              <span>{{ Question.tip[0] }}</span>
              <span>{{ Question.tip[1] }}</span>
            </div>
            <el-radio-group
              class="answer22"
              v-model="answerList[questionId][index]"
              v-for="(item, index2) in Question.choice"
            >
              <el-radio :label="index2.toString()">
                {{ item }}
              </el-radio>
            </el-radio-group>
          </div>
        </div>
      </el-card>
    </div>
  </div>
</template>

<script>
import { ref, getCurrentInstance, onMounted } from "vue";
import { question, alert1 } from "./e";
import { regionData } from "element-china-area-data";
import { checkAnswer, postAnswer } from "@/utils/api";
import { useRouter } from "vue-router";
let arr = [];
for (let i = 0; i < question.length; i++) {
  arr[i] = new Array(question[i].length).fill(null);
}
let arr2 = [];
for (let i = 0; i < question.length; i++) {
  arr2[i] = new Array(question[i].length).fill(1);
}
export default {
  data() {
    return {
      router: useRouter(),
      options: regionData,
      dialogTableVisible: false,
      questionList: question,
      alert1List: alert1,
      showList: arr2,
      answerList: arr,
      questionId: 0,
      group: "",
    };
  },
  computed: {
    currentQuestion: function () {
      return this.questionList[this.questionId];
    },
    tipwidth: function () {
      const l = this.questionList[this.questionId][0].choice.length * 75;
      return l.toString() + "px";
    },
  },
  beforeCreate() {
    checkAnswer("test4", 9).then((res) => {
      if (res.data.checked === 1) {
        this.router.push("/test1");
      }
    });
  },
  onMounted() {
    this.group = localStorage.getItem("group");
  },
  watch: {},
  methods: {
    checkIfAnswered(index) {
      let checked = true;
      for (let i = 0; i < this.answerList[index].length; i++) {
        if (this.answerList[index][i] === null) {
          checked = false;
          break;
        }
      }
      return checked;
    },
  },
};
</script>

<style lang="css">
.card-header {
  padding: 10px;
  font-size: 20px;
  margin-top: 30px;
  margin-right: 100px;
  text-align: right;
}

.answer {
  padding: 10px;
}

.question {
  padding: 10px 0;
}

.card-content {
  width: 90%;
  margin: 40px auto 0;
}

.card-content .box-card {
  text-align: left;
  padding-left: 50px;
}

.el-button.stu-answer-item {
  margin: 10px;
  width: 60px;
  height: 60px;
}
.answer22 {
  width: 80px;
}
.tip {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}
</style>
